<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<title>rbac-周边零食</title>


	<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">

	<link rel="stylesheet" href="./rbac/css/app.css">

	<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
	<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
	<!--[if lt IE 9]>
	  <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
	  <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
</head>
<body>

<!--导航条-->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
	<div class="container-fluid">
		<!-- Brand and toggle get grouped for better mobile display -->
		<div class="navbar-header">
			<a class="navbar-brand" href="adminLogin!login.action">rbac-周边零食</a>
		</div>

		<!-- Collect the nav links, forms, and other content for toggling -->
		<div class="collapse navbar-collapse">
			<ul class="nav navbar-nav">
				<li class="active"><a href="adminLogin!login.action">首页</a></li>
			</ul>

			<p class="navbar-text navbar-right">
			             欢迎进入，<%
                out.print(session.getValue("name"));
            %>
            </p>

		</div>
	</div>
</nav>

<!--菜单栏和内容区域-->
<div class="container-fluid">
	<div class="col-sm-2 col-md-2 col-lg-2 sidebar">
		<ul class="nav nav-sidebar">
			<li>数据表管理</li>
			<li><a href="userList!userList.action?page=1">用户列表</a></li>
			<li><a href="categoryList!categoryList.action">商品列表</a></li>
			<li><a href="productList!productList.action?page=1">产品列表</a></li>
			<li><a href="orderList!orderList.action?page=1">订单列表</a></li>
		</ul>
	</div>
	<div class="col-sm-10 col-sm-offset-2 col-md-10  col-md-offset-2 col-lg-10 col-lg-offset-2 main">
		<div class="row">
			<div class="col-xs-9 col-sm-9 col-md-9  col-lg-9">
				<h5>新增用户</h5>
			</div>
		</div>
		<hr/>
		<div class="row">
			<div class="form-horizontal user_set_wrap" role="form">
				<div class="form-group">
					<label class="col-xs-2 col-sm-2 col-md-2 col-lg-2 control-label">标题</label>
					<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
						<input type="text" class="form-control" name="title" placeholder="请输入标题" value="<s:property value="category.title"/>">
					</div>
				</div>
				<div class="form-group">
                    <label class="col-xs-2 col-sm-2 col-md-2 col-lg-2 control-label" >父亲序号</label>
                    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                        <input type="text" class="form-control" name="parentid" placeholder="父亲序号" value="<s:property value="category.parentid"/>">
                    </div>
                </div>
				<div class="col-xs-6 col-xs-offset-2 col-sm-6 col-sm-offset-2 col-md-6  col-md-offset-2 col-lg-6 col-sm-lg-2 ">
					<s:if test="%{category != null}">    
                         <input type="hidden" name="id"  value="<s:property value="category.cateid"/>">
                         <button type="button" class="btn btn-primary pull-right  save" onclick="update()">修改</button>
                    </s:if> 
				    <s:else>
                         <button type="button" class="btn btn-primary pull-right save" onclick="add()">添加</button>
				    </s:else>
				</div>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">

function update(){
    var title = $("input[name='title']").val();
    var parentid = $("input[name='parentid']").val();
    var id = $("input[name='id']").val();
    $.ajax({
        url:'categoryUpadte!categoryUpadte.action',
        type:'POST',
        data:{
        	id:id,
        	title:title,
        	parentid:parentid,
        },
        success:function( res ){
           //console.log(res.status)
           if(res.status==0){
               alert('修改成功');
               window.location.href = "categoryList!categoryList.action";
           }else{
               alert('修改失败，存在顶级不能修改哦，或者已经存在相同标题');
           }
        }
    });
}
function add(){
    var title = $("input[name='title']").val();
    var parentid = $("input[name='parentid']").val();
	$.ajax({
        url:'categoryAdd!categoryAdd.action',
        type:'POST',
        data:{
            title:title,
            parentid:parentid,
        },
        success:function( res ){
           //console.log(res.status)
           if(res.status==0){
        	   alert('添加成功');
        	   window.location.href = "categoryList!categoryList.action";
           }else{
        	   alert('添加失败');
           }
        }
    });
}
</script>
	<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
	<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>